
//
//  WSJSportDataRecordTableViewCell.m
//  RunningMan
//
//  Created by dllo on 16/5/23.
//  Copyright © 2016年 WSJ. All rights reserved.
//

#import "WSJSportDataRecordTableViewCell.h"
#define W self.frame.size.width
#define H self.frame.size.height

@interface WSJSportDataRecordTableViewCell ()

@property(nonatomic, retain)UIImageView *distanceImageView;
@property(nonatomic, retain)UIImageView *timeImageView;
@property(nonatomic, retain)UIImageView *caloriesImageView;
@property(nonatomic, retain)UIImageView *stepImageView;

@end

@implementation WSJSportDataRecordTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self creatView];
    }
    return self;
}

-(void)creatView{
    
    self.dataLabel = [[UILabel alloc] init];
    [self.contentView addSubview:self.dataLabel];
    self.dataLabel.font = [UIFont systemFontOfSize:22];
    self.dataLabel.textColor = [UIColor blueColor];
    
    self.distanceLabel = [[UILabel alloc] init];
    [self.contentView addSubview:self.distanceLabel];
    self.distanceLabel.font = [UIFont systemFontOfSize:20];
    
    
    self.timeLabel = [[UILabel alloc ] init];
    [self.contentView addSubview:self.timeLabel];

    self.caloriesLabel = [[UILabel alloc] init];
    [self.contentView addSubview:self.caloriesLabel];

    self.stepCountLabel = [[UILabel alloc] init];
    [self.contentView addSubview:self.stepCountLabel];
    
    
    self.distanceImageView = [[UIImageView alloc] init];
    self.distanceImageView.image = [UIImage imageNamed:@"distance.png"];
    [self.contentView addSubview:self.distanceImageView];
    
    self.timeImageView = [[UIImageView alloc] init];
    self.timeImageView.image = [UIImage imageNamed:@"time.png"];
    [self.contentView addSubview:self.timeImageView];
    
    self.caloriesImageView = [[UIImageView alloc] init];
    self.caloriesImageView.image = [UIImage imageNamed:@"calorie.png"];
    [self.contentView addSubview:self.caloriesImageView];
    
    self.stepImageView = [[UIImageView alloc] init];
    self.stepImageView.image = [UIImage imageNamed:@"foot.png"];
    [self.contentView addSubview:self.stepImageView];
  
    
    
    
}

-(void)layoutSubviews{
    [super layoutSubviews];
    self.dataLabel.frame = CGRectMake(20, 10, W - 20, 30);
    
    self.distanceLabel.frame = CGRectMake(40, 50, W / 2 - 50, 30);
    self.timeLabel.frame = CGRectMake(W / 2 + 40, 50, W / 2 - 50, 30);
    self.caloriesLabel.frame = CGRectMake(40, 90, W / 2 - 50, 30);
    self.stepCountLabel.frame = CGRectMake(W / 2 + 40, 90, W / 2 - 50, 30);
    
    
    self.distanceImageView.frame = CGRectMake(10, 55, 20, 20);
    self.timeImageView.frame = CGRectMake(W / 2 +10, 55, 20, 20);
    self.caloriesImageView.frame = CGRectMake(10 , 95, 20, 20);
    self.stepImageView.frame = CGRectMake(W / 2 + 10, 95, 20, 20);
    
    
}

-(void)setDataModel:(RunData *)dataModel{

    self.dataLabel.text = dataModel.timestamp;
    self.distanceLabel.text =  [NSString stringWithFormat:@"%@公里",dataModel.distance];
    
    NSInteger runtime = [dataModel.runtime integerValue];
    NSInteger hour = runtime / 3600;
    NSInteger min = runtime % 3600 / 60;
    NSInteger sec = runtime % 60;
    self.timeLabel.text = [NSString stringWithFormat:@"%02ld:%02ld:%02ld",hour, min,sec];
    
    CGFloat dis = [dataModel.distance floatValue];

    CGFloat calories = 60 * dis * 1036 ;
    if (calories < 1000) {
        self.caloriesLabel.text = [NSString stringWithFormat:@"%.1f cal", calories];
    }else{
        self.caloriesLabel.text = [NSString stringWithFormat:@"%.1f Kcal", calories / 1000.0];
    }
    
    self.stepCountLabel.text = [NSString stringWithFormat:@"%0.f步", dis * 1000 *100 / 60];
    
    
}




@end
